package cn.tedu.seri;

import java.io.Serializable;

/*本类用于封装学生类,用作测试序列化的物料类*/
/*如果本类的对象想要被序列化输出,那么本类必须实现可序列化接口,否则会报错
 * 报错信息:java.io.NotSerializableException: cn.tedu.seri.Student
 * Serializable接口是一个空接口,里面一个方法也没有,作用是当做标志,标志这个类可以被序列化*/ //标志这个类被序列化了实现了序列化
public class Student implements Serializable{


    private static final long serialVersionUID = 2874480762638453376L;

    /* private static final long serialVersionUID = 1L; //私有静态常量*/

    //1.1定义学生相关的属性+private封装
    private String name /*= "布索"*/;//姓名
    private int age;//年龄
    private String addr;//地址
    private char gender;//性别
//    private char gender2;//性别

    //2.1创建本类的无参构造
    public Student() {
        System.out.println("我是Student类的无参构造");
    }
    //2.2创建本类的全参构造
    public Student(String name, int age, String addr, char gender) {
        super();//Object的无参构造 //可以不写出来的默认调用父类的super(),
        this.name = name;
        this.age = age;
        this.addr = addr;
        this.gender = gender;
        System.out.println("我是Student类的全参构造");
    }

    /*public Student(String name, int age, String addr, char gender) {  //封装属性不影响全参构造
        this.name = name;
        this.age = age;
        this.addr = addr;
        this.gender = gender;
    }*/

    //1.2生成所有被封装属性的get与set方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }
    //为了查看Student类对象的类型+属性+属性值,而不是对象的地址值
    //我们需要在Student类中添加重写的toString()
    /*@Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", addr='" + addr + '\'' +
                ", gender=" + gender +
                '}';
    }*/
}
